home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Graphics Programming (2nd Edition)
/
Visual Basic Graphics Programming 2nd Edition.iso
/
OldSrc
/
CH3
/
SRC
/
PALPOPUP.FRM
< prev
next >
Wrap
Text File
|
1996-01-09
|
3KB
|
125 lines
VERSION 4.00
Begin VB.Form PalettePopup
AutoRedraw = -1 'True
BorderStyle = 1 'Fixed Single
ClientHeight = 3600
ClientLeft = 2505
ClientTop = 1575
ClientWidth = 3600
ControlBox = 0 'False
Height = 4005
Left = 2445
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3600
ScaleWidth = 3600
Top = 1230
Width = 3720
End
Attribute VB_Name = "PalettePopup"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private Const NO_COLOR = -1
Private selected_color As Integer
Private colors(0 To 255) As Long
Private dx As Single
Private dy As Single
' ***********************************************
' Fill the form with the palette colors and
' record their values in the colors array.
' ***********************************************
Public Sub Fill()
Dim i As Integer
Dim j As Integer
Dim clr As Integer
clr = 0
For i = 0 To 15
For j = 0 To 15
Line (j * dx, i * dy)-Step(dx, dy), _
clr + &H1000000, BF
colors(i * 16 + j) = Point(j * dx, i * dy)
clr = clr + 1
Next j
Next i
selected_color = NO_COLOR
End Sub
' ***********************************************
' Return the RGB value of the selected color.
' ***********************************************
Property Get SelectedColor() As Long
SelectedColor = colors(selected_color)
End Property
' ***********************************************
' Select the indicated color.
' ***********************************************
Private Sub SelectColor(ByVal i As Integer, ByVal j As Integer)
Dim oldi As Integer
Dim oldj As Integer
Dim oldmode As Integer
oldmode = DrawMode
DrawMode = vbInvert
' Erase the old selection if there is one.
If selected_color <> NO_COLOR Then
oldi = selected_color \ 16
oldj = selected_color Mod 16
Line (oldj * dx, oldi * dy)-Step(dx, dy)
Line (oldj * dx, (oldi + 1) * dy)-Step(dx, -dy)
End If
selected_color = i * 16 + j
' Highlight the new selection.
If selected_color <> NO_COLOR Then
Line (j * dx, i * dy)-Step(dx, dy)
Line (j * dx, (i + 1) * dy)-Step(dx, -dy)
End If
DrawMode = oldmode
End Sub
' ***********************************************
' Select a color with the indicated RGB value.
' ***********************************************
Property Let SelectedColor(ByVal clr As Long)
Dim i As Integer
' Take off the &H2000000.
clr = clr And &HFFFFFF
' Find a matching palette entry.
For i = 0 To 255
If colors(i) = clr Then Exit For
Next i
If i > 255 Then
' Unhighlight the previous selection.
SelectColor 0, NO_COLOR
Else
' Highlight the new selection.
SelectColor i \ 16, i Mod 16
End If
End Property
Private Sub Form_Load()
dx = ScaleWidth / 16
dy = ScaleHeight / 16
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SelectColor Y \ dy, X \ dx
Me.Hide
End Sub